// uView将所有的工具类全都放在uni.$u
const http = uni.$u.http

// 获取分类
const getClassify = () => http.get('/api/classify/get', {
	params: {
		projectId: 165
	}
})

// 根据分类ID获取文章
const getClassifyId = (id, limit) => http.get('/api/blog/searchByClassifyId', {
	params: {
		limit: limit || 6,
		id: id,
		projectId: 165,
		offset: 1
	}
})

// 登录
const login = (data) => http.post('/api/user/login', data)
// 注册
const register = (data) => http.post('/api/user/register', data)

// 修改个人信息
const edit = (data, token) => http.put('/api/user/edit', data, {
	header: {
		"x-token": token
	}
})

// 创建发布博客
const createBlog = (data, token) => http.post('/api/blog/create', data, {
	header: {
		"x-token": token
	}
})

// 关键词搜索
const getKeyword = (keyword) => http.get('/api/blog/searchByInput', {
	params: {
		keyword: keyword,
		projectId: 165
	}
})

// 博客详情页
const getDetail = (id, token) => http.get('/api/blog/search', {
	params: {
		id: id,
		projectId: 165
	},
	header: {
		"x-token": token
	}
})

// 创建评论
const creatComment = (data, token) => http.post('/api/comment/create', {
	projectId: 165,
	// projectId写死，打散data
	...data
}, {
	header: {
		"x-token": token
	}
})

// 获取评论
const getComment = (id, token) => http.get('/api/comment/get', {
	params: {
		id: id,
		projectId: 165
	},
	header: {
		"x-token": token
	}
})

// 点赞
const likeBlog = (id, token) => http.post('/api/blog/likeBlog', {
	id: id,
	projectId: 165
}, {
	header: {
		"x-token": token
	}
})
// 获取点赞的博客
const getLike=(token)=>http.get('/api/user/getLikeBlog',{
	header: {
		"x-token": token
	}
})

// 关注
const followBlog=(id,token)=>http.post('/api/user/follow',{
	id: id,
	projectId: 165
}, {
	header: {
		"x-token": token
	}
})
// 获取关注的用户
const getFollow=(token)=>http.get('/api/user/getLikeUser',{
	header: {
		"x-token": token
	}
})

// 获取自己的博客
const myBlog=(token)=>http.get('/api/blog/getMyBlog',{
	params: {
		projectId: 165
	},
	header: {
		"x-token": token
	}
})

export {
	getClassify,
	getClassifyId,
	login,
	getKeyword,
	register,
	edit,
	createBlog,
	getDetail,
	creatComment,
	getComment,
	likeBlog,
	followBlog,
	getLike,
	getFollow,
	myBlog
}
